package com.xu.cloud.common.format;

import com.xu.cloud.common.resource.XuCloudMessageSource;
import com.xu.cloud.common.util.ApplicationContextUtil;
import org.springframework.util.Assert;

/**
 * 国际化, 占位符: ${0}, ${1}, ...
 *
 * @author xuguan
 * @since 2024/1/22
 */
public class MessageSourceFormat implements IMessageFormat {

    @Override
    public String format(String messagePattern, Object[] args) {
        final XuCloudMessageSource messageSource = ApplicationContextUtil.getBean(XuCloudMessageSource.class);
        Assert.notNull(messageSource, "messageSource must not be null");

        return messageSource.getMessage(messagePattern, args);
    }
}
